$(function () {

    var edit_dialog =  $('#edit_dialog');
    var edit_form =  $('#edit_form');
    var recruit_datagrid =  $('#recruit_datagrid');
    //数据表格
    recruit_datagrid.datagrid({
        url:'/recruitInformation/list.do',
        striped:true,
        singleSelect:true,
        pagination:true,
        rownumbers:true,
        toolbar:"#tb",
        columns:[[
            {field:'cb',checkbox:true},
            {field:'id',hidden:true,width:100},
            {field:'username',title:'应聘人姓名',width:100},
            {field:'job',title:'应聘职位',width:100,align:'right'},
            {field:'employeeDate',title:'应聘日期',width:100,align:'right'},
            {field:'engage',title:'聘用类型',width:100,align:'right',formatter:hiretypeFoamatter},
            {field:'recruitNumber',title:'工作年数',width:100,align:'right'},
            {field:'education',title:'学历',width:100,align:'right',formatter:educationFormat},
            {field:'recruitSalary',title:'薪资要求',width:100,align:'right',formatter:recruitSalaryFormat},
            {field:'recruitRequired',title:'相关技能',width:100,align:'right'},
            {field:'remark',title:'备注',width:100,align:'right'}
        ]]
    });
    //end
    var cmdObj = {
        //添加按钮添加部门
        add : function () {

            edit_dialog.dialog("setTitle","添加职工");

            edit_form.form("clear");

            edit_dialog.dialog("open");
        },
        //编辑按钮编辑部门
        edit : function () {

            var row = recruit_datagrid.datagrid("getSelected");
            if (!row){
                $.messager.alert("温馨提示","请选择要编辑的职工","info");
                return;
            }

            edit_dialog.dialog("setTitle","编辑职工");

            //在读取数据之前,清除缓存
            edit_form.form("clear");

            //加工回显数据
            if(row.education){
                row["education.id"]=row.education.id;
            }
            if(row.recruitSalary){
                row["recruitSalary.id"]=row.recruitSalary.id;
            }
            if(row.engage){
                row["engage.id"]=row.engage.id;
            }
            edit_form.form("load",row);
            edit_dialog.dialog("open");
        },
        //save按钮提交表单
        save : function () {

            var url = "";

            var id = $("#recId").val();
            if(id){
                url = "/recruitInformation/update.do";
            }else{
                url = "/recruitInformation/save.do";
            }

            edit_form.form('submit', {
                url:url,
                success: function(data){
                    var data = eval('(' + data + ')');
                    if (data.success){
                        $.messager.confirm('温馨提示','操作成功',function(r){
                            edit_dialog.dialog("close");
                            recruit_datagrid.datagrid("load");
                        });
                    }else{
                        $.messager.alert("温馨提示",data.msg);
                    }
                }
            });
        },
        //编辑的关闭按钮功能
        cancel : function () {
            edit_dialog.dialog("close");
        },
        //刷新
        reload :function () {
            recruit_datagrid.datagrid("reload");
        },
        //高级查询
        //加载职工列表时,将多余查询条件一起发起请求
        searchT:function(){
            //加载列表数据时,携带额外参数
            recruit_datagrid.datagrid("load",{
                beginTime:$("#beginTime").val(),
                endTime:$("#endTime").val()
            })
        }

    };

    //抽取优化
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");

        cmdObj[cmd]();
    });
    //end


    //dialog弹窗
    edit_dialog.dialog({
        title: 'My Dialog',
        buttons:"#bb",
        closed:true,
        width: 750,
        height: 430
    });
    //end

});//end

//学历
function educationFormat(value,row,index) {
    return value ? value.name: "";
}

//聘用类型状况
function hiretypeFoamatter(value,row,index) {
    return value?value.name:"";
}
//薪资要求
function recruitSalaryFormat(value,row,index) {
    return value?value.name:"";
}








